component accessors="true" extends="controllerbase" {
	property uploader;
	this.entityObj = "uploader";
	
	public void function list(rc){
		var moduleSqlWhere = "";
		if( structKeyExists(rc, "clientname") && len(trim(rc.clientname)) >0 ){
			moduleSqlWhere = moduleSqlWhere & " and clientname like '%" & clientname & "%' " ;
		}
		
		super.list(rc,moduleSqlWhere);		
	}
	
	//上传文件
	public void function uploaderFiles(){
		
		if ( isNull( form.chunks ) ) {
			fileExtension = listLast( form.name, "." );
			clientName = form.name;
			serverName = createUUID() & "." & fileExtension;
			fileMove(form.file,expandPath( "/uploads/#serverName#" ));
	
		// 分块文件上传
		} else {
			// Since we are dealing with chunks, instead of a full file, we'll be appending each
			// chunk to the known file. However, for the demo, let's keep the transient file out
			// of the uploads until the chunking has been completed.
			
			clientName = form.name;
			fileExtension = listLast( form.name, "." );
			serverName = createUUID() & "." & fileExtension;
			
			upload = fileOpen( expandPath( "/chunks/#clientName#" ), "append" );
	
			// Append the current chunk to the end of the transient file.
			fileWrite( upload, fileReadBinary( form.file ) );
			fileClose( upload );
	
			// If this is the last of the chunks, the we can move the transient file to the 
			// completed uploads folder (with a unique name).
			if ( form.chunk == ( form.chunks - 1 ) ) {
				fileMove(
					expandPath( "/chunks/#clientName#" ),
					expandPath( "/uploads/#serverName#" )
				);
				
			}
		}
		
		//上传文件结构信息
		var uploaderFile = {};
		uploadFile.clientName 	= clientName;
		uploadFile.serverName 	= serverName;
		uploadFile.fileExt		= fileExtension;
		fileInfo = getFileInfo(expandPath("/uploads/#serverName#"));
		uploadFile.fileSize		= fileInfo.size;
		//如果是图片格式的，则获取图片信息，否则获取文件信息
		if(isimagefile(expandPath( "/uploads/#serverName#" ))){
			imgFileInfo = imageInfo(expandPath("/uploads/#serverName#"));
			uploadFile.fileWidth = imgFileInfo.width;
			uploadFile.fileHeight = imgFileInfo.height;
		}else{
			uploadFile.fileWidth = 0;
			uploadFile.fileHeight = 0;
		}
		rc.json = variables.uploader.uploaderFiles(uploadFile);
		variables.fw.renderData('json', rc.json);
	}
	
}